import Vue from 'vue'
import Router from 'vue-router'
import store from 'store';
import api from '@/assets/js/api'
var urlConfig = require('../../src/config');

Vue.use(Router)

const router = new Router({
  //mode: 'his tory',
  routes: [{
    path: '/',
    component: function (resolve) {
      require(['@/pages/bridge'], resolve)
    }
  },
    {
      path: '/1',
      component: function (resolve) {
        require(['@/pages/index-ios'], resolve)
      }
    },
    {
      path: '/2',
      component: function (resolve) {
        require(['@/pages/index-android'], resolve)
      }
    },
    {
      path: '/3',
      component: function (resolve) {
        require(['@/pages/index-zego'], resolve)
      }
    },
    {
      path: '/4',
      component: function (resolve) {
        require(['@/pages/artqiyi'], resolve)
      }
    },
    {
      path: '/roomIos/:device_id',
      component: function (resolve) {
        require(['@/pages/roomIos'], resolve)
      },
    },
    {
      path: '/room/:device_id',
      component: function (resolve) {
        require(['@/pages/room'], resolve)
      },
    },
    {
      path: '/order-list',
      meta: {
        title: '订单管理'
      },
      component: function (resolve) {
        require(['@/pages/order/list'], resolve)
      }
    },
    {
      path: '/order-detail',
      meta: {
        title: '订单详情'
      },
      component: function (resolve) {
        require(['@/pages/order/detail'], resolve)
      }
    },
    {
      path: '/delivery',
      meta: {
        title: '云+物娱'
      },
      component: function (resolve) {
        require(['@/pages/order/delivery'], resolve)
      }
    },
    {
      path: '/user-center',
      meta: {
        title: '我的'
      },
      component: function (resolve) {
        require(['@/pages/user-center/index'], resolve)
      }
    },
    {
      path: '/charge',
      meta: {
        title: '我的金币'
      },
      component: function (resolve) {
        require(['@/components/charge'], resolve)
      }
    }, {
      path: '/user-center/account',
      name: '/user-center/account',
      meta: {
        title: '充值记录'
      },
      component: function (resolve) {
        require(['@/pages/user-center/account'], resolve)
      }
    }, {
      path: '/user-center/consume',
      name: '/user-center/consume',
      meta: {
        title: '抓取记录'
      },
      component: function (resolve) {
        require(['@/pages/user-center/consume'], resolve)
      }
    },
    {
      path: '/mywawa',
      meta: {
        title: '我的娃娃'
      },
      component: function (resolve) {
        require(['@/pages/mywawa/my.vue'], resolve)
      }
    },
    {
      path: '/address-list',
      meta: {
        title: '收货地址'
      },
      component: function (resolve) {
        require(['@/pages/address/list.vue'], resolve)
      }
    },
    {
      path: '/add-address/',
      meta: {
        title: '编辑地址'
      },
      component: function (resolve) {
        require(['@/pages/address/add.vue'], resolve)
      }
    },
    {
      path: '/my-coin',
      meta: {
        title: '娃娃币'
      },
      component: function (resolve) {
        require(['@/pages/user-center/my-coin'], resolve)
      }
    },
  ]
});
router.beforeEach((to, from, next) => {
  if (to.path == '/order-list' || to.path == '/address-list' || to.path == '/mywawa' || to.path == '/add-address' || to.path == '/order-detail' || to.path == '/delivery') { //订单列表，娃娃机列表
    next()
  } else {
    if (to.query.api_token != '' && to.query.api_token != undefined) {
      store.set('apiToken', to.query.api_token);
    }
    // if (store.get('apiToken') == undefined || store.get('apiToken') == '') {
    //   let url = window.location.protocol + '//' + window.location.host + '/?#/';
    //   let uri = encodeURIComponent(url);
    //   window.location.href = urlConfig.wxLoginUrl + '/api/wechat/oauth?redirect_uri=' + uri;
    //   return;
    // }
  }
  if (to.meta.title) {
    window.document.title = to.meta.title;
  }
  next()

});
export default router;
